package cn.itcast.bos.web.action;


import java.security.Security;
import java.util.List;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.hibernate.cfg.beanvalidation.ActivationContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;

import cn.itcast.bos.domain.system.Menu;
import cn.itcast.bos.domain.system.User;
import cn.itcast.bos.service.MenuService;
import cn.itcast.bos.web.action.common.BaseAction;
import oracle.net.aso.p;

@ParentPackage(value="json-default")
@Namespace("/")
@Controller
@Scope("prototype")
public class MenuAction extends BaseAction<Menu> {

	@Autowired
	private MenuService menuService;
	/**
	 * 显示数据
	 */
	@Action(value = "menu_list", results = {@Result(name = "success", type = "json")})
	//@Action(value="menu_list",results = {@Result(name="success",type="json")})
	public String list() {
		List<Menu> list=menuService.findAll();
		//放入值栈
		ActionContext.getContext().getValueStack().push(list);
		return SUCCESS;
	}
	/**
	 * 保存方法
	 */
	@Action(value = "menu_save", results = {@Result(name = "success", type = "redirect",
			location="./pages/system/menu.html")})
	public String save() {
		menuService.save(model);
		return SUCCESS;
	}
	
	/**
	 * 首页根据登录不同,显示不同菜单
	 * 
	 */
	// 加载左侧的菜单功能
	@Action(value="menu_showMenu",results={@Result(name="success",type="json")})
	public  String showMenu() {
		// 调用业务层，查询当前用户具有菜单列表
		Subject subject = SecurityUtils.getSubject();
		User user =(User) subject.getPrincipal();
		//查询菜单列表
		List<Menu> list=menuService.findByUser(user);
		ActionContext.getContext().getValueStack().push(list);
		return SUCCESS;
	}
	
}






